<template>
	<view class="box">
		<view class="list_box">
			<span>公司名称</span>
			<input class="inp_box" type="text" v-model="asr.companyName"/>
		</view>
			
		<view class="list_box">
			<button ></button>
			<span>营业执照</span>
			<view class="" @click="uploadpic(1)">
				<uni-file-picker
					:value="businessLicense"
					  return-type="object"
					 file-mediatype="image"
					    mode="grid"
					    file-extname="png,jpg"
					    :limit="1"
					    @progress="progress" 
					    @success="success" 
					    @fail="fail" 
					    @select="select"
					disabled='false'
				/>
			</view>
			
		</view>
		<view class="list_box">
			<span > 农业登记证</span>
	
			<view class="" @click="uploadpic(2)">
				<uni-file-picker
					:value="registrationCertificate"
					  return-type="object"
					 file-mediatype="image"
					    mode="grid"
					    file-extname="png,jpg"
					    :limit="1"
					    @progress="progress" 
					    @success="success" 
					    @fail="fail" 
					    @select="select"
						disabled='false'
							/>
			</view>
		
		</view>
		<view class="list_box">
			<span>业务联系人</span>
			<input class="inp_box" type="text" v-model="asr.businessContact"/>
		</view>
		<view class="list_box">
			<span>电话</span>
			<input class="inp_box" type="tel" v-model="asr.contactPhoneNumber"/>
		</view>
		<view class="list_box">
			<span>地址</span>
			<input class="inp_box" type="text" v-model="asr.addres"/>
		</view>
		<view class="list_box">
			<span>区域</span>
			<input class="inp_box" type="text" v-model="asr.region"/>
		</view>
		<view class="list_box">
			<span>收货联系人</span>
			<input class="inp_box" type="text" v-model="asr.receivingContactPerson"/>
		</view>
		<view class="list_box">
			<span>收货联系人电话</span>
			<input class="inp_box" type="text" v-model="asr.receivingContactPhoneNumber"/>
		</view>
		<view class="list_box">
			<span>销售员</span>
			<input class="inp_box" type="text" v-model="asr.salesperson"/>
		</view>
		
		
		<button type="primary" style="width: 100%; height:60rpx;position: absolute;bottom:50rpx;left: 0px;text-align: center;line-height: 60rpx;" @click="creat()">保存</button>
	</view>
</template>

<script>
	import {personalData,personalDatas,personalUpload} from '@/api/api.js'
import uFilePicker from '@/components/uFilePicker/uFilePicker.vue'
export default {
	components: {
		uFilePicker
	},
	data() {
		return {
			urls:'',
			businessLicense:[],
			registrationCertificate:[],
				asr:{
					// businessLicense:'',
					// registrationCertificate:'',
				}
		};
	},
	created(){
	this.querys()
	},
	methods: {
		uploadpic(index) {
			let that = this;
			that.$util.uploadImageOne({
				url: 'user/upload/image',
				name: 'multipart',
				model: "user",
				pid: 7,
				
			}, function(res) {
				if(index==1){
					that.businessLicense=[]
					that.businessLicense.push({
						 "url":res.data.url,
						 "name":"file.jpg",
						"extname":"jpg",
					})
					that.urls=res.data.url
					// that.asr.businessLicense=res.data.url
				}else{
					that.registrationCertificate=[]
					that.registrationCertificate.push({
						 url:res.data.url,
						 name:"file.jpg",
						extname:"jpg",
					})
					// that.asr.registrationCertificate=res.data.url
				
					}
			});
			console.log(that.businessLicense)
			console.log(that.businessLicense[0].url)
		},
		querys(){
			let that=this
			that.businessLicense=[]
			that.registrationCertificate=[]
			personalDatas().then(res=>{
				that.asr=res.data
				that.urls=res.data.businessLicense
				that.businessLicense.push({
					 "url":res.data.businessLicense,
					 "name":"file.jpg",
					"extname":"jpg",
				})
				that.registrationCertificate.push({
					 "url":res.data.registrationCertificate,
					 "name":"file.jpg",
					"extname":"jpg",
				})
	
			})
		},
	 creat(){
			let that = this
			let prop={
				companyName:that.asr.companyName,
				businessContact:that.asr.businessContact,
				contactPhoneNumber:that.asr.contactPhoneNumber,
				region:that.asr.region,
				addres:that.asr.addres,
				receivingContactPerson:that.asr.receivingContactPerson,
				businessLicense:that.businessLicense[0].url?that.businessLicense[0].url:"",
				registrationCertificate:that.registrationCertificate[0].url?that.registrationCertificate[0].url:"",
				receivingContactPhoneNumber:that.asr.receivingContactPhoneNumber,
				salesperson:that.asr.salesperson
			}
				// if(typeof that.businessLicense.url=="object"){
				// 	prop.businessLicense=''
				// }else if(typeof that.businessLicense.url=="object"){
				// 	prop.registrationCertificate=''
				// }
			personalData(prop).then(res=>{
				that.pd=1
				uni.showToast({
								title: '保存成功',
								icon:'exception',
								duration:850
							});
							setTimeout(
							function(){
								uni.switchTab({
									url: '/pages/goods_cate/goods_cate'
								})
							},1000)
					
			})
				
		}
	}
};
</script>

<style scoped lang="scss">
.box {
	padding: 20rpx;

	.list_box {
		margin-bottom: 10px;
		
		.inp_box {
			border-bottom: 1px solid #ccc;
		}
	}
}
</style>